package com.wanbatv.wangwangba.model.imple;

import android.content.Context;


import com.wanbatv.wangwangba.model.MainModel;
import com.wanbatv.wangwangba.model.OnMainListener;
import com.wanbatv.wangwangba.model.entity.AuthenticationData;
import com.wanbatv.wangwangba.model.entity.DogtvData;
import com.wanbatv.wangwangba.model.entity.EncyclopediasData;
import com.wanbatv.wangwangba.model.entity.HomepageData;
import com.wanbatv.wangwangba.model.entity.OrderData;
import com.wanbatv.wangwangba.model.entity.PayData;
import com.wanbatv.wangwangba.model.entity.TrailerData;
import com.wanbatv.wangwangba.model.entity.WangwangshowData;
import com.wanbatv.wangwangba.model.entity.WechatData;
import com.wanbatv.wangwangba.util.Config;
import com.wanbatv.wangwangba.util.GitMainService;
import com.wanbatv.wangwangba.util.GitWechatService;
import com.wanbatv.wangwangba.util.HeaderClient;
import com.wanbatv.wangwangba.util.Product;
import com.wanbatv.wangwangba.util.Util;

import java.util.List;


import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;


/**
 * Created by 俞亚楠 on 2016/7/19.
 */
public class MainModelImple implements MainModel {
    Context context;
    public MainModelImple(Context context){
        this.context=context.getApplicationContext();
    }

    Retrofit retrofit =new Retrofit.Builder()
            .baseUrl(Config.httpUrl())
            .addConverterFactory(GsonConverterFactory.create())
            .client(HeaderClient.genericClient())
            .build();
    GitMainService api=retrofit.create(GitMainService.class);


    @Override
    public void setHomepageData(final OnMainListener onMainListener) {

        api.getHomepage().enqueue(new Callback<HomepageData>() {
            @Override
            public void onResponse(Call<HomepageData> call, Response<HomepageData> response) {
                List<HomepageData.DataBean.ListBean> list=response.body().getData().getList();
                onMainListener.onLoadHomepageData(list);
            }

            @Override
            public void onFailure(Call<HomepageData> call, Throwable t) {

            }
        });


    }



    @Override
    public void setDogtvData(final OnMainListener onMainListener) {
        api.getDogtvprograms().enqueue(new Callback<DogtvData>() {
            @Override
            public void onResponse(Call<DogtvData> call, Response<DogtvData> response) {
                List<DogtvData.DataBean.ListBean> listBeen=response.body().getData().getList();
                onMainListener.onLoadDagtvData(listBeen);
            }

            @Override
            public void onFailure(Call<DogtvData> call, Throwable t) {

            }
        });
    }

    @Override
    public void setEncyclopedias(final OnMainListener onMainListener) {
        api.getEncyclopedias().enqueue(new Callback<EncyclopediasData>() {
            @Override
            public void onResponse(Call<EncyclopediasData> call, Response<EncyclopediasData> response) {
                List<EncyclopediasData.DataBean.ListBean> listBeen=response.body().getData().getList();
                onMainListener.onLoadEncyclopediasData(listBeen);
            }

            @Override
            public void onFailure(Call<EncyclopediasData> call, Throwable t) {

            }
        });
    }

    @Override
    public void setWangwangshow(OnMainListener onMainListener) {
        api.getShows().enqueue(new Callback<WangwangshowData>() {
            @Override
            public void onResponse(Call<WangwangshowData> call, Response<WangwangshowData> response) {

            }

            @Override
            public void onFailure(Call<WangwangshowData> call, Throwable t) {

            }
        });
    }

    @Override
    public void setTrailer(final OnMainListener onMainListener) {
        api.getTrailer(Product.flavor).enqueue(new Callback<TrailerData>() {
            @Override
            public void onResponse(Call<TrailerData> call, Response<TrailerData> response) {
                List<TrailerData.DataBean.LoopPlaylistBean> loopPlaylistBeen=response.body().getData().getLoop_playlist();
                onMainListener.onloadTrailerData(loopPlaylistBeen);
            }

            @Override
            public void onFailure(Call<TrailerData> call, Throwable t) {

            }
        });
    }



//           }
}
